<?php

namespace App\Admin\Controllers;

use App\Admin\Forms\ComprehensiveQueryImport;
use App\Admin\Forms\DoubleProtectionImport;
use App\Admin\Forms\UserAwardPunishImport;
use App\Admin\Forms\UserMonthTargetImport;
use App\Admin\Repositories\UserMonthTarget;
use App\Admin\Services\ErpRepairSettlementService;
use App\Admin\Services\PositionMonthTargetService;
use App\Admin\Services\UserMonthTargetService;
use App\Models\PositionMonthTargetItem;
use App\Models\Store;
use App\Models\User;
use App\Models\UserMonthAwardPunish;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Dcat\Admin\Widgets\Modal;

class UserMonthTargetController extends AdminController
{
    protected $erp_meet_car_count = 0;
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(UserMonthTarget::with(['user', 'positionMonthTarget']), function (Grid $grid) {
            $position_month_target_id = request()->get('position_month_target_id');
            $target = PositionMonthTargetService::one($position_month_target_id);

            $grid->model()->where('position_month_target_id', request()->get('position_month_target_id'));

            $grid->tools(function (Grid\Tools $tools) {
                $tools->append(Modal::make()
                    // 大号弹窗
                    ->lg()
                    // 弹窗标题
                    ->title('上传文件')
                    // 按钮
                    ->button('<button class="btn btn-primary"><i class="feather icon-upload"></i> 导入员工月目标</button>')
                    // 弹窗内容
                    ->body(UserMonthTargetImport::make()));
                $tools->append(Modal::make()
                    // 大号弹窗
                    ->lg()
                    // 弹窗标题
                    ->title('上传文件')
                    // 按钮
                    ->button('<button class="btn btn-primary"><i class="feather icon-upload"></i> 导入双保保养</button>')
                    // 弹窗内容
                    ->body(DoubleProtectionImport::make()));
                $tools->append(Modal::make()
                    // 大号弹窗
                    ->lg()
                    // 弹窗标题
                    ->title('上传文件')
                    // 按钮
                    ->button('<button class="btn btn-primary"><i class="feather icon-upload"></i> 导入综合查询维修</button>')
                    // 弹窗内容
                    ->body(ComprehensiveQueryImport::make()));
                $tools->append(Modal::make()
                    // 大号弹窗
                    ->lg()
                    // 弹窗标题
                    ->title('上传文件')
                    // 按钮
                    ->button('<button class="btn btn-primary"><i class="feather icon-upload"></i> 导入员工月奖罚</button>')
                    // 弹窗内容
                    ->body(UserAwardPunishImport::make()));
            });

            $grid->column('id')->sortable();
            $grid->column('user.name', admin_trans('user-month-target.fields.user_id'));
//            $grid->column('meet_car_vehicle_target');

            if ($target->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                $maintenance_vehicle_target_lang = admin_trans('user-month-target.fields.append_target');
                $meet_car_commission_coefficient_lang = admin_trans('user-month-target.fields.working_hours_coefficient');
                $output_value_commission_coefficient_lang = admin_trans('user-month-target.fields.append_commission');
            } else {
                $maintenance_vehicle_target_lang = admin_trans('user-month-target.fields.maintenance_vehicle_target');
                $meet_car_commission_coefficient_lang = admin_trans('user-month-target.fields.meet_car_commission_coefficient');
                $output_value_commission_coefficient_lang = admin_trans('user-month-target.fields.output_value_commission_coefficient');
            }

            $grid->column('meet_car_commission_coefficient', $meet_car_commission_coefficient_lang)->display(function () {
                if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                    return $this->positionMonthTarget->meet_car_commission_coefficient;
                } else {
                    return $this->meet_car_commission_coefficient;
                }
            });
            $grid->column('output_value_commission_coefficient', $output_value_commission_coefficient_lang)->display(function () {
                if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                    return $this->positionMonthTarget->output_value_commission_coefficient;
                } else {
                    return $this->output_value_commission_coefficient;
                }
            });
            $grid->column('output_value_target');

            $grid->column('maintenance_vehicle_target', $maintenance_vehicle_target_lang);
            $grid->column('updated_at')->sortable();
            $grid->tools('<a href="/admin/user-month-target/create?position_month_target_id='.request()->get('position_month_target_id').'" style="float: right;" class="btn btn-primary">新增</a>');
            $grid->disableCreateButton();


            $grid->filter(function (Grid\Filter $filter) use ($target) {
                $filter->equal('id');
                $filter->equal('user_id')->select(User::where('position_id', $target->position_id)->pluck('name', 'id'));
            });

            $grid->disableBatchDelete();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        \Dcat\Admin\Admin::style('.control-label {font-size: 12.5px;}.col-sm-2 {flex: 0 0 20%;max-width: 20%;}');
        return Show::make($id, UserMonthTarget::with(['user', 'positionMonthTarget']), function (Show $show) use ($id) {
            $target = \App\Models\UserMonthTarget::find($id);

            $show->row(function (Show\Row $show) {
                $show->width(6)->id;
                $show->width(6)->target_date;
            });
            $show->row(function (Show\Row $show) use ($target) {
                $show->width(6)->field('user.name', admin_trans('user-month-target.fields.user_id'));
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //接车台次
                    $show->width(6)->field('erp_meet_car_count', admin_trans('user-month-target.fields.erp_meet_car_count'))->as(function () use (&$new_erp_meet_car_count) {
                        $this->erp_meet_car_count = ErpRepairSettlementService::erpMeetCarCount([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        return $this->erp_meet_car_count;
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //工时
                    $show->width(6)->field('erp_machine_repair_working_hours', admin_trans('user-month-target.fields.erp_machine_repair_working_hours'))->as(function () use (&$new_erp_meet_car_count) {
                        $this->erp_machine_repair_working_hours = ErpRepairSettlementService::erpMachineRepairWorkingHours([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        return $this->erp_machine_repair_working_hours;
                    });
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //接车提成系数
                    $show->width(6)->field('meet_car_commission_coefficient')->as(function () {
                        if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                            $this->meet_car_commission_coefficient = $this->positionMonthTarget->meet_car_commission_coefficient;
                        }

                        return $this->meet_car_commission_coefficient;
                    });
                    //接车提成
                    $show->width(6)->field('erp_meet_car_commission', admin_trans('user-month-target.fields.erp_meet_car_commission'))->as(function () {
                        $this->erp_meet_car_commission = $this->erp_meet_car_count * $this->meet_car_commission_coefficient;
                        return $this->erp_meet_car_commission.'元';
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //工时提成系数
                    $show->width(6)->field('meet_car_commission_coefficient', admin_trans('user-month-target.fields.working_hours_coefficient'))->as(function () {
                        if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                            $this->meet_car_commission_coefficient = $this->positionMonthTarget->meet_car_commission_coefficient;
                        }

                        return $this->meet_car_commission_coefficient.'%';
                    });
                    //工时提成金额
                    $show->width(6)->field('erp_meet_car_commission', admin_trans('user-month-target.fields.working_hours_coefficient_price'))->as(function () {
                        $this->erp_meet_car_commission = $this->erp_machine_repair_working_hours * 120 * ($this->meet_car_commission_coefficient/100);
                        return $this->erp_meet_car_commission.'元';
                    });
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //产值实际(万)
                    $show->width(6)->field('real_output_value', admin_trans('user-month-target.fields.real_output_value'))->as(function () {
                        $this->real_output_value = ErpRepairSettlementService::erpRealOutputValue([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        $score = PositionMonthTargetItem::where('position_month_target_id', $this->position_month_target_id)
                            ->where('user_id', $this->user_id)
                            ->sum('score');

                        $this->real_output_value = ($this->real_output_value + $score)/10000;

                        return $this->real_output_value.'万';
                    });
                    //产值提成系数（%）
                    $show->width(6)->field('output_value_commission_coefficient')->as(function () {
                        if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                            $this->output_value_commission_coefficient = $this->positionMonthTarget->output_value_commission_coefficient;
                        }

                        return $this->output_value_commission_coefficient.'%';
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //追加
                    $show->width(6)->field('append_value', admin_trans('user-month-target.fields.append_value'))->as(function () {
                        $this->append_value = ErpRepairSettlementService::erpAppendValue([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        return sprintf("%.2f", $this->append_value/10000);
                    });
                    //追加提成百分比
                    $show->width(6)->field('output_value_commission_coefficient', admin_trans('user-month-target.fields.append_commission'))->as(function () {
                        if ($this->positionMonthTarget->is_commission_coefficient_status == DEFAULT_STATUS_SUCCESS) {
                            $this->output_value_commission_coefficient = $this->positionMonthTarget->output_value_commission_coefficient;
                        }

                        return $this->output_value_commission_coefficient.'%';
                    });
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //产值业绩提成
                    $show->width(6)->field('output_value_achievement_commission', admin_trans('user-month-target.fields.output_value_achievement_commission'))->as(function () {
                        $this->output_value_achievement_commission = sprintf("%.2f",($this->real_output_value*10000) * ($this->output_value_commission_coefficient/100));
                        return $this->output_value_achievement_commission.'元';
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //追加业绩提成
                    $show->width(6)->field('output_value_achievement_commission', admin_trans('user-month-target.fields.append_commission_price'))->as(function () {
                        $this->output_value_achievement_commission = sprintf("%.2f", $this->append_value * ($this->output_value_commission_coefficient / 100));
                        return $this->output_value_achievement_commission . '元';
                    });
                }

                //产值目标
                $show->width(6)->field('output_value_target')->as(function () {
                    return $this->output_value_target.'万';
                });
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //产值实际
                    $show->width(6)->field('real_output_values', admin_trans('user-month-target.fields.real_output_value'))->as(function () {
                        return $this->real_output_value.'万';
                    });
                    //达成率
                    $show->width(6)->field('output_value_reach', admin_trans('user-month-target.fields.output_value_reach'))->as(function () {
                        $this->output_value_reach = ((($this->real_output_value*10000) / $this->output_value_target) / 100);
                        return sprintf("%.2f",$this->output_value_reach).'%';
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //产值实际
                    $show->width(6)->field('real_output_value', admin_trans('user-month-target.fields.real_output_value'))->as(function () {
                        $this->real_output_value = ErpRepairSettlementService::erpRepairRealOutputValue([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        return sprintf("%.2f", $this->real_output_value/10000).'万';
                    });
                    //达成率
                    $show->width(6)->field('output_value_reach', admin_trans('user-month-target.fields.output_value_reach'))->as(function () {
                        $this->output_value_reach = (($this->real_output_value / $this->output_value_target) / 100);
                        return sprintf("%.2f",$this->output_value_reach).'%';
                    });
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //得分
                    $show->width(6)->field('output_value_score', admin_trans('user-month-target.fields.output_value_score'))->as(function () {
                        if ($this->output_value_reach >= 100) {
                            $this->output_value_score = '0.4';
                        } elseif ($this->output_value_reach >= 90 && $this->output_value_reach <= 100) {
                            $this->output_value_score = '0.35';
                        } else {
                            $this->output_value_score = '0.3';
                        }

                        return $this->output_value_score;
                    });
                    //定保台次目标
                    $show->width(6)->field('maintenance_vehicle_target');
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //得分
                    $show->width(6)->field('output_value_score', admin_trans('user-month-target.fields.output_value_score'))->as(function () {
                        if ($this->output_value_reach >= 100) {
                            $this->output_value_score = '0.65';
                        } elseif ($this->output_value_reach >= 90 && $this->output_value_reach <= 100) {
                            $this->output_value_score = '0.50';
                        } else {
                            $this->output_value_score = '0.45';
                        }

                        return $this->output_value_score;
                    });
                    //追加目标
                    $show->width(6)->field('maintenance_vehicle_target', admin_trans('user-month-target.fields.append_target'));
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //定保台次实际
                    $show->width(6)->field('real_maintenance_vehicle', admin_trans('user-month-target.fields.real_maintenance_vehicle'))->as(function () {
                        $this->real_maintenance_vehicle = ErpRepairSettlementService::erpRealMaintenanceVehicle([
                            'user_erp_id' => $this->user->erp_id,
                            'target_date' => $this->target_date,
                            'store_erp_id' => $this->user->store->erp_id
                        ]);

                        return $this->real_maintenance_vehicle;
                    });
                    //定保台次达成率（%）
                    $show->width(6)->field('maintenance_vehicle_reach', admin_trans('user-month-target.fields.maintenance_vehicle_reach'))->as(function () {
                        $this->maintenance_vehicle_reach = ($this->real_maintenance_vehicle / $this->maintenance_vehicle_target) * 100;
                        return sprintf("%.2f", $this->maintenance_vehicle_reach) . '%';
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //追加实际
                    $show->width(6)->field('real_maintenance_vehicle', admin_trans('user-month-target.fields.append_value_real'))->as(function () {
                        return sprintf("%.2f", $this->append_value/10000);
                    });
                    //追加达成率
                    $show->width(6)->field('maintenance_vehicle_reach', admin_trans('user-month-target.fields.append_value_reach'))->as(function () {
                        $this->maintenance_vehicle_reach = (($this->append_value/10000) / $this->maintenance_vehicle_target) * 100;
                        return sprintf("%.2f", $this->maintenance_vehicle_reach) . '%';
                    });
                }
            });
            $show->row(function (Show\Row $show) use ($target) {
                if ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                    //定保台次得分
                    $show->width(6)->field('maintenance_vehicle_score', admin_trans('user-month-target.fields.maintenance_vehicle_score'))->as(function () {
                        if ($this->maintenance_vehicle_reach >= 100) {
                            $this->maintenance_vehicle_score = '0.7';
                        } elseif ($this->maintenance_vehicle_reach >= 90 && $this->maintenance_vehicle_reach <= 100) {
                            $this->maintenance_vehicle_score = '0.5';
                        } else {
                            $this->maintenance_vehicle_score = '0.4';
                        }

                        return $this->maintenance_vehicle_score;
                    });
                } elseif ($target->positionMonthTarget->position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                    //追加得分
                    $show->width(6)->field('maintenance_vehicle_score', admin_trans('user-month-target.fields.append_value_score'))->as(function () {
                        if ($this->maintenance_vehicle_reach >= 100) {
                            $this->maintenance_vehicle_score = '0.4';
                        } elseif ($this->maintenance_vehicle_reach >= 90 && $this->maintenance_vehicle_reach <= 100) {
                            $this->maintenance_vehicle_score = '0.35';
                        } else {
                            $this->maintenance_vehicle_score = '0.3';
                        }

                        return $this->maintenance_vehicle_score;
                    });
                }
                //KPI
                $show->width(6)->field('kpi_coefficient', admin_trans('user-month-target.fields.kpi_coefficient'))->as(function () {
                    $this->kpi_coefficient = $this->output_value_score + $this->maintenance_vehicle_score;
                    return $this->kpi_coefficient;
                });
            });
            $show->row(function (Show\Row $show) {
                //奖励
                $show->width(6)->field('user_month_award', admin_trans('user-month-target.fields.user_month_award'))->as(function () {
                    $this->user_month_award = UserMonthAwardPunish::where('position_month_target_id', $this->position_month_target_id)
                        ->where('user_id', $this->user_id)
                        ->where('type', DEFAULT_TYPE_ONE)
                        ->sum('price');

                    return $this->user_month_award;
                });
                //罚款
                $show->width(6)->field('user_month_punish', admin_trans('user-month-target.fields.user_month_punish'))->as(function () {
                    $this->user_month_punish = UserMonthAwardPunish::where('position_month_target_id', $this->position_month_target_id)
                        ->where('user_id', $this->user_id)
                        ->where('type', DEFAULT_TYPE_TWO)
                        ->sum('price');

                    return $this->user_month_punish;
                });
            });
            $show->row(function (Show\Row $show) {
                //绩效工资小计
                $show->width(6)->field('subtotal_merit_pay', admin_trans('user-month-target.fields.subtotal_merit_pay'))->as(function () {
                    $this->subtotal_merit_pay = ($this->erp_meet_car_commission + $this->output_value_achievement_commission) * $this->kpi_coefficient + $this->user_month_award - $this->user_month_punish;
                    return sprintf("%.2f", $this->subtotal_merit_pay);
                });
                //售后部门毛利目标达成率
                $show->width(6)->field('gross_profit_reach', admin_trans('user-month-target.fields.gross_profit_reach'))->as(function () {
                    $this->gross_profit_reach = $this->positionMonthTarget->gross_profit_reach;
                    return $this->gross_profit_reach.'%';
                });
            });
            $show->row(function (Show\Row $show) {
                $show->width(6)->field('should_merit_pay', admin_trans('user-month-target.fields.should_merit_pay'))->unescape()->as(function () {
                    $this->should_merit_pay = sprintf("%.2f",$this->subtotal_merit_pay * ($this->gross_profit_reach / 100));
                    if ($this->user->probation_period_end_time && ($this->user->probation_period_end_time > $this->target_date.'-01')) {
                        return "<span style='text-decoration:line-through'>{$this->should_merit_pay}</span>";
                    } else {
                        return $this->should_merit_pay;
                    }
                });
                $show->width(6)->field('basic_salary', admin_trans('user-month-target.fields.basic_salary'))->unescape()->as(function () {
                    if ($this->user->probation_period_end_time && ($this->user->probation_period_end_time > $this->target_date.'-01')) {
                        return "<span style='text-decoration:line-through'>{$this->user->basic_salary}</span>";
                    } else {
                        return $this->user->basic_salary;
                    }
                });
            });
            $show->row(function (Show\Row $show) use ($target) {
                $show->width(6)->field('total_salary', admin_trans('user-month-target.fields.total_salary'))->unescape()->as(function () {
                    $total_salary = sprintf("%.2f",$this->should_merit_pay + $this->user->basic_salary);

                    if ($this->user->probation_period_end_time && ($this->user->probation_period_end_time > $this->target_date.'-01')) {
                        return "<span style='text-decoration:line-through'>{$total_salary}</span>";
                    } else {
                        return $total_salary;
                    }
                });

                if ($target->user->probation_period_end_time && ($target->user->probation_period_end_time > $target->target_date.'-01')) {
                    $show->field('user.probation_period_salary', admin_trans('user-month-target.fields.probation_period_salary'));
                }
            });

            $show->panel()
                ->tools(function ($tools) {
                    $tools->disableEdit();
                    $tools->disableList();
                    $tools->disableDelete();
                });
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserMonthTarget(), function (Form $form) {
            if ($form->isEditing()) {
                $target = $form->model();
                $position_month_target_id = $target->position_month_target_id;
                $position_target = PositionMonthTargetService::one($position_month_target_id);
                $position_type = $position_target->position_type;
                $position_id = $position_target->position_id;
                $target->is_commission_coefficient_status = $position_target->is_commission_coefficient_status;
            } else {
                $target = PositionMonthTargetService::one(request()->get('position_month_target_id'));
                $position_type = $target->position_type;
                $position_month_target_id = $target->id;
                $position_id = $target->position_id;
            }

            $form->select('user_id')->options(User::where('position_id', $position_id)->pluck('name', 'id'));

            if ($target->is_commission_coefficient_status == DEFAULT_STATUS_FAILURE) {
                $form->text('meet_car_commission_coefficient');
                $form->text('output_value_commission_coefficient');
            } else {
                $form->hidden('meet_car_commission_coefficient')->value($target->meet_car_commission_coefficient);
                $form->hidden('output_value_commission_coefficient')->value($target->output_value_commission_coefficient);
            }

            $form->text('output_value_target');

            if ($position_type == POSITION_TYPE_SERVICE_RECEPTION) {
                $maintenance_vehicle_target_lang = 'maintenance_vehicle_target';
            } elseif ($position_type == POSITION_TYPE_SERVICE_MACHINE_REPAIR) {
                $maintenance_vehicle_target_lang = 'append_target';
            }

            $form->text('maintenance_vehicle_target', admin_trans("user-month-target.fields.$maintenance_vehicle_target_lang"));
            $form->hidden('target_date')->value($target->target_date);
            $form->hidden('position_month_target_id')->value($position_month_target_id);

            $form->saving(function ($form) {
                unset($form->model()->is_commission_coefficient_status);

                $param['id'] = $form->model()->id ?? 0;
                $param['target_date'] = $form->target_date;
                $param['user_id'] = $form->user_id;
                $param['position_month_target_id'] = $form->position_month_target_id;

                $is_target = UserMonthTargetService::isTarget($param);

                if ($is_target) {
                    return $form->response()->error('该用户目标月份信息已经存在!');
                }
            });

            $form->saved(function ($form) {
                return $form->response()->success('保存成功')->redirect('user-month-target?position_month_target_id='.$form->position_month_target_id);
            });

            $form->footer(function ($footer) {
                $footer->disableReset();
                $footer->disableViewCheck();
                $footer->disableEditingCheck();
            });

            $form->tools(function (Form\Tools $tools) use ($position_month_target_id) {
                $tools->disableList();
                $tools->disableView();
                $tools->disableDelete();
                $tools->append('<a href="/admin/user-month-target?position_month_target_id='.$position_month_target_id.'" class="btn btn-sm"><i class="fa fa-list"></i>&nbsp;&nbsp;列表</a>');
            });
        });
    }
}
